 
<!-- 分享生活页面 -->
<template>
  <div>
    <myheader title="生活趣事" rightBtn="发表动态" @updataInfo="goHome"></myheader>
    <div class="serarch">
      <van-search v-model="searchValue" show-action placeholder="请输入搜索关键词" @search="onSearch" />
    </div>
    <div class="sharelife">
      <div v-if="!empty">
        <van-pull-refresh v-model="loading" success-text="刷新成功" @refresh="onRefresh">
          <!-- <van-list
            v-model="loading"
            :finished="finished"
            finished-text="wdnmd,没数据了别刷了"
            @load="onLoad"
            :immediate-check="false"
          >-->
          <van-cell>
            <share-life :dynamic="dynamic" @updata="updata"></share-life>
          </van-cell>
          <!-- </van-list> -->
        </van-pull-refresh>
      </div>
      <van-empty v-else image="error" description="暂无此内容！" />
    </div>
  </div>
</template>

<script>
import myheader from '../../../comon/myheader.vue'
import ShareLife from '../../../comon/sharelifeItem.vue'

export default {
  components: {
    myheader,
    ShareLife,
  },
  data() {
    return {
      dynamic: [],
      current: 1, //记录第几页
      total: 10, //记录全部的数据
      pages: 1,
      loading: false, // 下拉刷新
      searchValue: '',
      empty: true,
    }
  },
  created() {
    this.init()
  },
  methods: {
    async init() {
      if (this.$store.getters.getUserInfo) {
        const res = await this.$axios.get(
          '/dynamic/list?current=' +
            this.current +
            '&userId=' +
            this.$store.getters.getUserInfo.id
        )
        if (res.data.code == 200) {
          this.dynamic = res.data.data.records
          this.pages = res.data.pages
          this.current = res.data.current
          this.empty = false
        }
      } else {
        const res = await this.$axios.get(
          '/dynamic/list?current=' + this.current
        )
        if (res.data.code == 200) {
          this.dynamic = res.data.data.records
          this.pages = res.data.pages
          this.current = res.data.current
          this.empty = false
        }
      }
    },
    // 刷新
    onRefresh() {
      this.loading = false
      if (this.current++ < this.pages) {
        this.current++
      }
      this.init()
    },
    async onSearch() {
      const res = await this.$axios.get(
        '/dynamic/list?title=' + this.searchValue
      )
      if (res.data.code == 200) {
        this.dynamic = res.data.data.records
        this.searchValue = ''
        if (this.dynamic.length == 0) {
          this.empty = true
        } else {
          this.empty = false
        }
      }
    },
    updata() {
      this.init()
    },
    // onLoad(){

    // },
    goHome() {
      this.$router.push('/addSharelife')
    },
  },
}
</script>

<style  scoped>
.sharelife {
  margin-top: 96px;
}
.serarch {
  position: fixed;
  top: 46px;
  width: 100vw;
  z-index: 999;
}
</style>>
 